package com.zxy.express.service.impl;

import com.autopai.base.common.mybatis.service.impl.BaseServiceImpl;
import com.autopai.base.common.web.constant.Constant;
import com.autopai.base.common.web.convert.ConvertUtils;
import com.autopai.base.common.web.page.PageData;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zxy.express.dao.AudioCollectionDao;
import com.zxy.express.dao.AudioEpisodeDao;
import com.zxy.express.dto.AudioCollectionDTO;
import com.zxy.express.dto.AudioEpisodeDTO;
import com.zxy.express.entity.AudioCollectionEntity;
import com.zxy.express.entity.AudioEpisodeEntity;
import com.zxy.express.service.AudioCollectionService;
import com.zxy.express.service.AudioEpisodeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 合集
 *
 * @author zhangxiying ${email}
 * @since ${version} 2025-07-01
 */
@Service
public class AudioCollectionServiceImpl extends BaseServiceImpl<AudioCollectionDao, AudioCollectionEntity> implements AudioCollectionService {

    @Override
    public PageData<AudioCollectionDTO> page(Map<String, Object> params) {
        IPage<AudioCollectionEntity> page = baseDao.selectPage(
                getPage(params, "sort", true),
                getWrapper(params)
        );

        return getPageData(page, AudioCollectionDTO.class);
    }

    @Override
    public List<AudioCollectionDTO> list(Map<String, Object> params) {
        List<AudioCollectionEntity> entityList = baseDao.selectList(getWrapper(params));

        return ConvertUtils.sourceToTarget(entityList, AudioCollectionDTO.class);
    }

    private QueryWrapper<AudioCollectionEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<AudioCollectionEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);
        String collectionId=(String)params.get("");
        return wrapper;
    }

    @Override
    public AudioCollectionDTO get(String id) {
        AudioCollectionEntity entity = baseDao.selectById(id);

        return ConvertUtils.sourceToTarget(entity, AudioCollectionDTO.class);
    }

    @Override
    public void save(AudioCollectionDTO dto) {
        AudioCollectionEntity entity = ConvertUtils.sourceToTarget(dto, AudioCollectionEntity.class);

        insert(entity);
        dto.setId(entity.getId());
    }

    @Override
    public void update(AudioCollectionDTO dto) {
        AudioCollectionEntity entity = ConvertUtils.sourceToTarget(dto, AudioCollectionEntity.class);

        updateById(entity);
    }

    @Override
    public void delete(String[] ids) {
        //逻辑删除
        //logicDelete(ids, MaterialEntity.class);

        //物理删除
        baseDao.deleteBatchIds(Arrays.asList(ids));
    }

}